package edu.bu.cs511.p5;

/** 
 * This is the most useful debugging opcode as it can very easily
 * simulate opcodes that take a specific amount of (configurable) time
 * to run in.<p/>
 */
public class LongOpcode implements IOpcode {
    private String id;
    private int timeout;

    /**
     * Constructor to create the DemoTask.<p/>
     *
     * @REQUIRES id is an identification of this opcode to be
     * reported in usage statistics and timeout is the amount of time
     * this opcode should execute every time it is invoked.
     *
     */
    public LongOpcode(String id, int timeout) {
        this.id = id;
        this.timeout = timeout;
    }

    /** 
     * Execute an opcode.
     *
     * @MODIFIES: Execute for a time defined by the timeout pass in to
     * the constructor and notify the SchedulerDemo class that we have
     * executed.
     */
    public void execute() {
        try {
            Thread.sleep(timeout);
        } catch (Exception e) {
            System.out.println("e = " + e);
        }
        System.out.print(id);
    }

    /**
     * An accessor method return if the opcode is currently enabled or
     * not.</p>
     *
     * @EFFECTS return true if the opcode is enabled, false otherwise.
     */
    public boolean isEnabled() {
        return true;
    }
}
